home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / dix / RCS / dixutils.c,v < prev    next >
Encoding:
Text File  |  1990-02-14  |  8.2 KB  |  349 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.15.23.20;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49.  
  50.  
  51. /* $XConsortium: dixutils.c,v 1.35 89/09/30 10:46:46 keith Exp $ */
  52.  
  53. #include "X.h"
  54. #include "Xmd.h"
  55. #include "misc.h"
  56. #include "window.h"
  57. #include "dixstruct.h"
  58. #include "pixmapstr.h"
  59. #include "scrnintstr.h"
  60. #define  XK_LATIN1
  61. #include "keysymdef.h"
  62.  
  63. /*
  64.  * CompareTimeStamps returns -1, 0, or +1 depending on if the first
  65.  * argument is less than, equal to or greater than the second argument.
  66.  */
  67.  
  68. int
  69. CompareTimeStamps(a, b)
  70.     TimeStamp a, b;
  71. {
  72.     if (a.months < b.months)
  73.     return EARLIER;
  74.     if (a.months > b.months)
  75.     return LATER;
  76.     if (a.milliseconds < b.milliseconds)
  77.     return EARLIER;
  78.     if (a.milliseconds > b.milliseconds)
  79.     return LATER;
  80.     return SAMETIME;
  81. }
  82.  
  83. /*
  84.  * convert client times to server TimeStamps
  85.  */
  86.  
  87. #define HALFMONTH ((unsigned long) 1<<31)
  88. TimeStamp
  89. ClientTimeToServerTime(c)
  90.      CARD32 c;
  91. {
  92.     TimeStamp ts;
  93.     if (c == CurrentTime)
  94.     return currentTime;
  95.     ts.months = currentTime.months;
  96.     ts.milliseconds = c;
  97.     if (c > currentTime.milliseconds)
  98.     {
  99.     if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH)
  100.         ts.months -= 1;
  101.     }
  102.     else if (c < currentTime.milliseconds)
  103.     {
  104.     if (((unsigned long)currentTime.milliseconds - c) > HALFMONTH)
  105.         ts.months += 1;
  106.     }
  107.     return ts;
  108. }
  109.  
  110. /*
  111.  * ISO Latin-1 case conversion routine
  112.  *
  113.  * this routine always null-terminates the result, so
  114.  * beware of too-small buffers
  115.  */
  116.  
  117. void
  118. CopyISOLatin1Lowered(dest, source, length)
  119.     register unsigned char *dest, *source;
  120.     int length;
  121. {
  122.     register int i;
  123.  
  124.     for (i = 0; i < length; i++, source++, dest++)
  125.     {
  126.     if ((*source >= XK_A) && (*source <= XK_Z))
  127.         *dest = *source + (XK_a - XK_A);
  128.     else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
  129.         *dest = *source + (XK_agrave - XK_Agrave);
  130.     else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
  131.         *dest = *source + (XK_oslash - XK_Ooblique);
  132.     else
  133.         *dest = *source;
  134.     }
  135.     *dest = '\0';
  136. }
  137.  
  138. WindowPtr
  139. LookupWindow(rid, client)
  140.     XID rid;
  141.     ClientPtr client;
  142. {
  143.     client->errorValue = rid;
  144.     if(rid == INVALID)
  145.     return NULL;
  146.     if (client->lastDrawableID == rid)
  147.     {
  148.         if (client->lastDrawable->type != DRAWABLE_PIXMAP)
  149.             return ((WindowPtr) client->lastDrawable);
  150.         return (WindowPtr) NULL;
  151.     }
  152.     return (WindowPtr)LookupIDByType(rid, RT_WINDOW);
  153. }
  154.  
  155.  
  156. pointer
  157. LookupDrawable(rid, client)
  158.     XID rid;
  159.     ClientPtr client;
  160. {
  161.     register DrawablePtr pDraw;
  162.  
  163.     if(rid == INVALID)
  164.     return (pointer) NULL;
  165.     if (client->lastDrawableID == rid)
  166.     return ((pointer) client->lastDrawable);
  167.     pDraw = (DrawablePtr)LookupIDByClass(rid, RC_DRAWABLE);
  168.     if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW))
  169.         return (pointer)pDraw;        
  170.     return (pointer)NULL;
  171. }
  172.  
  173.  
  174. int
  175. AlterSaveSetForClient(client, pWin, mode)
  176.     ClientPtr client;
  177.     WindowPtr pWin;
  178.     unsigned mode;
  179. {
  180.     int numnow;
  181.     pointer *pTmp;
  182.     int j;
  183.  
  184.     numnow = client->numSaved;
  185.     j = 0;
  186.     if (numnow)
  187.     {
  188.     pTmp = client->saveSet;
  189.     while ((j < numnow) && (pTmp[j] != (pointer)pWin))
  190.         j++;
  191.     }
  192.     if (mode == SetModeInsert)
  193.     {
  194.     if (j < numnow)         /* duplicate */
  195.        return(Success);
  196.     numnow++;
  197.     pTmp = (pointer *)xrealloc(client->saveSet, sizeof(pointer) * numnow);
  198.     if (!pTmp)
  199.         return(BadAlloc);
  200.     client->saveSet = pTmp;
  201.            client->numSaved = numnow;
  202.     client->saveSet[numnow - 1] = (pointer)pWin;
  203.     return(Success);
  204.     }
  205.     else if ((mode == SetModeDelete) && (j < numnow))
  206.     {
  207.     while (j < numnow-1)
  208.     {
  209.            pTmp[j] = pTmp[j+1];
  210.        j++;
  211.     }
  212.     numnow--;
  213.         if (numnow)
  214.     {
  215.             pTmp = (pointer *)xrealloc(client->saveSet,
  216.                        sizeof(pointer) * numnow);
  217.         if (pTmp)
  218.         client->saveSet = pTmp;
  219.     }
  220.         else
  221.         {
  222.             xfree(client->saveSet);
  223.         client->saveSet = (pointer *)NULL;
  224.     }
  225.     client->numSaved = numnow;
  226.     return(Success);
  227.     }
  228.     return(Success);
  229. }
  230.  
  231.  
  232. DeleteWindowFromAnySaveSet(pWin)
  233.     WindowPtr pWin;
  234. {
  235.     register int i;
  236.     register ClientPtr client;
  237.     
  238.     for (i = 0; i< currentMaxClients; i++)
  239.     {    
  240.     client = clients[i];
  241.     if (client && client->numSaved)
  242.         (void)AlterSaveSetForClient(client, pWin, SetModeDelete);
  243.     }
  244. }
  245.  
  246. /* No-op Don't Do Anything : sometimes we need to be able to call a procedure
  247.  * that doesn't do anything.  For example, on screen with only static
  248.  * colormaps, if someone calls install colormap, it's easier to have a dummy
  249.  * procedure to call than to check if there's a procedure 
  250.  */
  251. void
  252. NoopDDA()
  253. {
  254. }
  255.  
  256. typedef struct _BlockHandler {
  257.     void    (*BlockHandler)();
  258.     void    (*WakeupHandler)();
  259.     pointer blockData;
  260. } BlockHandlerRec, *BlockHandlerPtr;
  261.  
  262. static BlockHandlerPtr    handlers;
  263. static int        numHandlers;
  264. static int        sizeHandlers;
  265.  
  266. /* called from the OS layer */
  267. BlockHandler(pTimeout, pReadmask)
  268. pointer    pTimeout;    /* DIX doesn't want to know how OS represents time */
  269. pointer pReadmask;    /* nor how it represents the set of descriptors */
  270. {
  271.     register int i;
  272.     
  273.     for (i = 0; i < screenInfo.numScreens; i++)
  274.     (* screenInfo.screens[i]->BlockHandler)(i, 
  275.                 screenInfo.screens[i]->blockData,
  276.                 pTimeout, pReadmask);
  277.     for (i = 0; i < numHandlers; i++)
  278.     (*handlers[i].BlockHandler) (handlers[i].blockData,
  279.                      pTimeout, pReadmask);
  280. }
  281.  
  282.  
  283. WakeupHandler(result, pReadmask)
  284. unsigned long    result;    /* 32 bits of undefined result from the wait */
  285. pointer pReadmask;    /* the resulting descriptor mask */
  286. {
  287.     register int i;
  288.     for (i = numHandlers - 1; i >= 0; i--)
  289.     (*handlers[i].WakeupHandler) (handlers[i].blockData,
  290.                       result, pReadmask);
  291.     for (i = 0; i < screenInfo.numScreens; i++)
  292.     (* screenInfo.screens[i]->WakeupHandler)(i, 
  293.                 screenInfo.screens[i]->wakeupData,
  294.                 result, pReadmask);
  295. }
  296.  
  297. Bool
  298. RegisterBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
  299.     void    (*blockHandler)();
  300.     void    (*wakeupHandler)();
  301.     pointer blockData;
  302. {
  303.     BlockHandlerPtr new;
  304.  
  305.     if (numHandlers >= sizeHandlers)
  306.     {
  307.         new = (BlockHandlerPtr) xrealloc (handlers, (numHandlers + 1) *
  308.                             sizeof (BlockHandlerRec));
  309.         if (!new)
  310.         return FALSE;
  311.         handlers = new;
  312.     sizeHandlers = numHandlers + 1;
  313.     }
  314.     handlers[numHandlers].BlockHandler = blockHandler;
  315.     handlers[numHandlers].WakeupHandler = wakeupHandler;
  316.     handlers[numHandlers].blockData = blockData;
  317.     numHandlers = numHandlers + 1;
  318.     return TRUE;
  319. }
  320.  
  321. void
  322. RemoveBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
  323.     void    (*blockHandler)();
  324.     void    (*wakeupHandler)();
  325.     pointer blockData;
  326. {
  327.     int        i;
  328.  
  329.     for (i = 0; i < numHandlers; i++)
  330.     if (handlers[i].BlockHandler == blockHandler &&
  331.         handlers[i].WakeupHandler == wakeupHandler &&
  332.         handlers[i].blockData == blockData)
  333.     {
  334.         for (; i < numHandlers - 1; i++)
  335.         handlers[i] = handlers[i+1];
  336.         numHandlers--;
  337.         break;
  338.     }
  339. }
  340.  
  341. InitBlockAndWakeupHandlers ()
  342. {
  343.     xfree (handlers);
  344.     handlers = (BlockHandlerPtr) 0;
  345.     numHandlers = 0;
  346.     sizeHandlers = 0;
  347. }
  348. @
  349.